package app.fugema.shop.main.goods.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.base.common.netBeanPackage.LiveDataWrapper;
import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.connector.OnItemClickInterface;
import com.base.common.view.base.BaseTitleActivity;
import com.base.common.viewmodel.BaseViewObserver;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ActivityShopCateBinding;
import app.fugema.shop.main.goods.adapter.ShopCateAdapter;
import app.fugema.shop.main.goods.model.VShopCateResult;
import app.fugema.shop.main.goods.vm.ShopVM;

/**
 * 店铺分类
 */
public class ShopCateActivity extends BaseTitleActivity<ActivityShopCateBinding, ShopVM>
{

    private ShopCateAdapter adapter;

    //微店id
    private int shopId;

    public static void start(Context context , int shopId)
    {
        Intent intent = new Intent(context, ShopCateActivity.class);
        intent.putExtra("shopId", shopId);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_cate);
    }

    @Override
    protected int getStatusBarColor()
    {
        return R.color.redColor;
    }

    @Override
    protected void initView()
    {
        setCloseImg(R.mipmap.ic_back_white);
        setTitle("店铺分类",R.color.white);
        adapter = new ShopCateAdapter();
        adapter.setOnItemClickInterface(new OnItemClickInterface() {
            @Override
            public boolean onItemClick(View view, int onclickType, int itemType, int position, Object bean) {
                if (view.getId() == R.id.tv_shop_cate)
                {


                    return true;
                }
                return false;
            }
        });
        binding.rvRecyclerView.setAdapter(adapter);


    }


    @Override
    protected void initData(Intent intent)
    {
        shopId = intent.getIntExtra("shopId", 0);
        getShopCates(shopId);
    }



    public void getShopCates(int mShopId)
    {
        viewModel.getShopCategoryById(mShopId).observe(this, new BaseViewObserver<LiveDataWrapper<VShopCateResult>>(viewUtils.getStateLayout()) {
            @Override
            protected void onSuccess(LiveDataWrapper<VShopCateResult> data)
            {
                adapter.setDataList(data.data.getShopCategories());
            }

            @Override
            public boolean isEmptyData(LiveDataWrapper<VShopCateResult> data)
            {
                return  UIUtils.isEmpty( data.data.getShopCategories());
            }

        });
    }


}
